<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link href="/URMS/lib/layui-v2.5.5/css/layui.css" media="all" rel="stylesheet">
    <link href="/URMS/css/public.css" media="all" rel="stylesheet">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body style="align-content:  center;">
<form class="layui-form layuimini-form" style="text-align: center;width: 800px">
    <div class="layui-form-item">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="账号不能为空" lay-verify="required" name="account" placeholder="请输入账号"
                   type="text">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">

            <input class="layui-input" lay-reqtext="用户名不能为空" lay-verify="required" name="name" placeholder="请输入用户名"
                   type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="密码不能为空" lay-verify="required" name="password" placeholder="请输入密码"
                   type="password">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">再次输入密码</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="密码不能为空" lay-verify="required" name="password2" placeholder="请输入密码"
                   type="password">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input lay-skin="switch" lay-text="可用|禁用" name="status" type="checkbox">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-filter="saveBtn" lay-submit>确认保存</button>
        </div>
    </div>
</form>
<script charset="utf-8" src="/URMS/lib/layui-v2.5.5/layui.js"></script>
<script>

    layui.use(['form', 'layer'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            if (data.field.status == "on") {
                data.field.status = "1";
            } else {
                data.field.status = "0";
            }
            let user = data.field

            layer.confirm(JSON.stringify(data.field), function () {
                '最终的提交信息',
                    $.ajax({
                        url: "/URMS/sysUser/addUserSubmit",
                        data: user,
                        type: "POST",
                        dataType: "JSON",
                        error: function (XMLHttpResponse) {
                            layer.msg("添加出错");
                        },
                        success: function (data) {
                            if (data == "添加成功") {
                                layer.msg("添加成功");
                                // layer.close(index);
                                let iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);

                                return false
                            } else {
                                layer.msg("添加失败")
                            }
                        }
                    })
            })
        });
    });


</script>
</body>
</html>